package service;

import modelo.CajaDao;
import entities.CajaEntity;
import beans.CajaBean;

public class CajaSrv {

	private static CajaSrv instancia = null;
		
		public static CajaSrv getInstancia() {
			if(instancia == null) {
				instancia = new CajaSrv();
			}
			return instancia;
		}

		public void guardarCaja(CajaBean cajaBean) {
		CajaEntity cajaEntity = this.bean2Entity(cajaBean);
		CajaDao.getInstancia().merge(cajaEntity);	
		}

		public CajaEntity bean2Entity(CajaBean cajaBean) {
			CajaEntity cajaEntity = new CajaEntity();
			cajaEntity.setCupones(cajaBean.getCupones());
			cajaEntity.setEfectivo(cajaBean.getEfectivo());
			cajaEntity.setTarjetaCredito(cajaBean.getTarjetaCredito());
			cajaEntity.setTarjetaDebito(cajaBean.getTarjetaDebito());
			cajaEntity.setId(cajaBean.getId());
			return cajaEntity;
		}
			
		
		public CajaBean entity2Bean(CajaEntity cajaEntity) {
			CajaBean cajaBean = new CajaBean();
			cajaBean.setCupones(cajaEntity.getCupones());
			cajaBean.setEfectivo(cajaEntity.getEfectivo());
			cajaBean.setTarjetaCredito(cajaEntity.getTarjetaCredito());
			cajaBean.setTarjetaDebito(cajaEntity.getTarjetaDebito());
			cajaBean.setId(cajaEntity.getId());
			return cajaBean;
		}
		
}
